import java.io.IOException;

import com.google.appengine.api.datastore.DatastoreService;
import com.google.appengine.api.datastore.DatastoreServiceFactory;
import com.google.appengine.api.datastore.Entity;
import com.google.appengine.tools.remoteapi.RemoteApiInstaller;
import com.google.appengine.tools.remoteapi.RemoteApiOptions;


class GaeAuthentication {
	private static RemoteApiInstaller installer;
	private static int refcnt = 0;
	private static Object lock = new Object();

	GaeAuthentication() throws IOException {
		synchronized(lock) {
			if (refcnt++ == 0) {
				String username = "common.cloud.project";
				String password = "cloudcomp";

				RemoteApiOptions options = new RemoteApiOptions()
					.server("cc-assign3.appspot.com", 443)
					.credentials(username, password);

				installer = new RemoteApiInstaller();
				installer.install(options);
			}
		}
	}

	public void close() {
		synchronized(lock) {
			if (--refcnt == 0)
				installer.uninstall();
		}
	}
};

